import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

class PieChartWidget extends StatefulWidget {
  const PieChartWidget({super.key});

  @override
  State<PieChartWidget> createState() => _PieChartState();
}

class _PieChartState extends State<PieChartWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(20),
      color: Colors.tealAccent,
      child: Center(
        child: PieChart(
            PieChartData(
                centerSpaceRadius:60,
              centerSpaceColor: Colors.white,
              borderData: FlBorderData(show: false),
              sections:showingSections(),
                startDegreeOffset:90
            )
        ),
      ),
    );
  }


  List<PieChartSectionData> showingSections(){
    return [
      PieChartSectionData(
        color: Colors.blue,
        value:35,
        title: '35%',
        radius:160,
        titleStyle: TextStyle(fontSize:20, fontWeight: FontWeight.bold, color: Colors.white,decoration: TextDecoration.none),
      ),
      PieChartSectionData(
        color: Colors.red,
        value:25,
        title: '25%',
        radius:160,
        titleStyle: TextStyle(fontSize:20, fontWeight: FontWeight.bold, color: Colors.white,decoration: TextDecoration.none),
      ),
      PieChartSectionData(
        color: Colors.green,
        value:20,
        title: '20%',
        radius:160,
        titleStyle: TextStyle(fontSize:20, fontWeight: FontWeight.bold, color: Colors.white,decoration: TextDecoration.none),
      ),
      PieChartSectionData(
        color: Colors.yellow,
        value:15,
        title: '老人\n15%',
        radius:160,
        titleStyle: TextStyle(fontSize:20, fontWeight: FontWeight.bold, color: Colors.white,decoration: TextDecoration.none,fontFamily: 'Arial',),
      ),

      PieChartSectionData(
        color: Colors.yellow,
        value:5,
        title: '5%',
        radius:160,
        titleStyle: TextStyle(fontSize:20, fontWeight: FontWeight.bold, color: Colors.white,decoration: TextDecoration.none),
      ),
    ];
  }
}
